package com.lekang.web.util;

import java.security.SecureRandom;

/**
 * 验证码生成工具类
 */
public class VerifyCodeUtils {

    // 验证码长度（6位数字）
    private static final int CODE_LENGTH = 6;
    // 验证码字符集（仅数字，避免混淆）
    private static final String CODE_CHARS = "0123456789";

    /**
     * 生成随机6位数字验证码
     */
    public static String generateEmailCode() {
        SecureRandom random = new SecureRandom();
        StringBuilder code = new StringBuilder();
        for (int i = 0; i < CODE_LENGTH; i++) {
            // 随机取字符集中的字符
            int index = random.nextInt(CODE_CHARS.length());
            code.append(CODE_CHARS.charAt(index));
        }
        return code.toString();
    }
}